<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:include page="/common/commonCss.jsp" />
<jsp:include page="/common/commonJs.jsp" />
<script language="javascript" src="${basePath}commonJs/tags/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="${basePath }commonJs/verify.js"></script>
<script type="text/javascript">
	$(document).ready(function (){
		$("#branIdSelect option[value='${branId}']").attr("selected",true);
		refreshSelect();
		$("#fkBranId").val("${branId}");
		createTable();
	}); 

	function createTable()
	{
		var pkTskIdVal = $.trim($("#pkTskIdVal").val());
		$("#pkTskId").val(pkTskIdVal);
		
		var startTime = $.trim($("#startTime").val());
		$("#startSearchTime").val(startTime);
		var endTime = $.trim($("#endTime").val());
		$("#endSearchTime").val(endTime);
		
		var form = $("#scmTakeForm");
		var pagenbean = new PageBean(form);
		pagenbean.setTableId("scmTakeTable");
		pagenbean.setCallback(initList);
		pagenbean.setFootId("scmTakeFoot");
		setPagebeanObj(pagenbean);
		pagenbean.doPage();
	}
	
	//分页数据解析
	function initList(data)
	{
		if(data==null)
			{
				return;
			}
		var verify = isVerify("${basePath }", "stock:delete4");
		trimJsonArray(data);
		$.each(data, function(ind,obj){
			var i = ind + 1;
			var date;
			var time;
			if(obj.takeTime != null && obj.takeTime !="")
				{
					date = new Date(obj.takeTime);
					time = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
				}else
				{
					time = "";
				}
			var pkTskId = obj.pkTskId;
			var htm = "<tr>";
			htm += "<td>" + i + "</td>";
			htm += "<td class='lv'><a href='#' pkTskId='"+pkTskId+"' onclick='toStockTakingDetail(this);'>"+pkTskId+"</td>";
			htm += "<td>" + time + "</td>";
			htm += "<td>" + obj.usrName + "</td>";
			htm += "<td>" + obj.prdCnt + "</td>";
			htm += "<td>" + obj.branName + "</td>";
			htm += "<td>" + (obj.diffCnt == "" ? 0 :  obj.diffCnt)+ "</td>";
			if(verify)
				{
				htm += "<td><input type='button' class='btn_l' value='删除' onclick=\"delTake(this);\" pkTskId="+pkTskId+"></td></tr>";
				}
			else
				{
				htm += "<td></td></tr>";
				}
			$("#scmTakeTable").find("tr:eq(" + ind + ")").after(htm);
		});
	}
	
	function toStockTakingDetail(obj)
	{
		$("#tskIdVal").val($(obj).attr("pkTskId"));
		$("#toStockTakingDetail").submit();
	}

	//删除
	function delTake(obj)
	{
		$.messager.confirm('警告', $common_confirm_delete, function(r) {
			if (r) {
				var pkTskId = $(obj).attr("pkTskId");
				$.ajax({
					url:"${basePath}StockTaking/delStockTake.shtml",
					data:{"pkTskId":pkTskId},
					dataType:"text",
					type:"post",
					async:false,
					success:function (result)
					{
						if(result == 1)
						{
							alertInfo($common_delete_success);
							createTable();
						}
						if(result == 0)
						{
							alertError($common_delete_failure);
						}
					},
					error : function(XMLHttpRequest) {
						ajaxError(XMLHttpRequest);
					}
				});	
			}
		});
	}
	
	//更换门店
	function branSelectFun() {
		$("#fkBranId").val($("#branIdSelect").val());
	}
</script>
<title>嘉童游乐中心-库存盘点</title>

</head>
<body class="bg"> 
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
            <shiro:hasPermission name="StockGoodsIn/toStock_goodsIn.shtml">
				<li><a href="${basePath}StockGoodsIn/toStock_goodsIn.shtml"><i class="nav_icon_b"></i><br>商品入库</a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="StockQuery/toStockQuery.shtml">
				<li><a href="${basePath}StockQuery/toStockQuery.shtml"><i class="nav_icon_b"></i><br>库存查询</a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="StockGoodsOut/toStockGoodsOut.shtml">
				<li><a href="${basePath}StockGoodsOut/toStockGoodsOut.shtml"><i class="nav_icon_b"></i><br>商品出库</a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="StockTaking/toStockTaking.shtml">
				<li class="content_hover"><a href="${basePath}StockTaking/toStockTaking.shtml"><i class="nav_icon_a"></i><br>库存盘点</a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="StockCorrect/toStockCorrect.shtml">
				<li><a href="${basePath}StockCorrect/toStockCorrect.shtml"><i class="nav_icon_f"></i><br>库存调整</a></li>
			</shiro:hasPermission>
        </ul>
    </div>
    <div class="content_r mt10">
    	<div class="p20">
    	<div class="file_single_dl f14 fixed">
        	<dl class="fixed" style="overflow:hidden">
            	<dd><label>盘点编号：</label><input type="text" class="iput_t w200" id="pkTskIdVal"></dd>
               <dd><label>盘点时间：</label><input type="text" id="startTime" class="Wdate iput_t w82" onClick="WdatePicker({dateFmt:'yyyy/MM/dd',isShowWeek:true,isShowClear:true,readOnly:true})">
               <span>至</span><input type="text" id="endTime" class="Wdate iput_t w82" onClick="WdatePicker({dateFmt:'yyyy/MM/dd',isShowWeek:true,isShowClear:true,readOnly:true})"></dd>
               <dd><label>所属门店：</label>
             		<!----select--->
               	 	<div class="uboxstyle">
                     	<select name="branIdSelect" id="branIdSelect" onchange="branSelectFun();">
                     		<c:forEach items="${branList}" var="bran">
                     			<option value="${bran.pkBranId}">${bran.branName}</option>
                     		</c:forEach>
                     	</select>
                		 </div>
                	 <!----select--->
             	</dd>
                <dd class="fr">
                <input type="button" class="btn ml10 fr" value="查询" onclick="createTable();">
                <shiro:hasPermission name="stock:add4">
                <input class="btn ml10 fr" type="button" value="开始盘点" onclick="javascript:window.location.href='${basePath}StockTaking/toStockAddStockTaking.shtml'">
                </shiro:hasPermission>
                </dd>
            </dl>
            
        </div>
        <!-- 表单  -->
       	<form action="${basePath}StockTaking/findScmTakeStk.shtml" id="scmTakeForm">
       		<input type="hidden" name="pageSize" value="10"> 
       		<input type="hidden" name="pageNo" value="1"> 
       		<input type="hidden" name="pkTskId" id="pkTskId"> 
       		<input type="hidden" name="startSearchTime" id="startSearchTime"> 
       		<input type="hidden" name="endSearchTime" id="endSearchTime"> 
       		<input type="hidden" name="fkBranId" id="fkBranId">
       	</form>
       		
       	<form action="${basePath}StockTaking/toStockTakingDetail.shtml" id="toStockTakingDetail">
       		<input type="hidden" name="pkTskId" id="tskIdVal"> 
       	</form>
       	 <!-- 表单  -->
        <table class="table" id="scmTakeTable">
                    	<tr>
                        	<th>序号</th>
                            <th>盘点编号</th>
                            <th>盘点时间</th>
                            <th>盘点人</th>
                            <th>商品项数</th>
                            <th>盘点仓库</th>
                            <th>差异商品项数</th>
                            <th>操作</th>
                        </tr>
                        
                    </table>
                 <!----翻页----->
                 <div class="page fr m10" id="scmTakeFoot"></div>
                 <!----翻页----->
    </div>
</div>
</div>
</body>
</html>